﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Windows.Forms;
using FaceRecognition.DataBase;
using FaceRecognition.View;

namespace FaceRecognition.Models
{
    class Train_manager
    {
        
        public void insert_Train_feature(Int32 User_id, string Feature)
        {
            try
            {
            using(DataClasses1DataContext db = new DataClasses1DataContext())
            {
            Train_Feature TR = new Train_Feature();
            TR.Features = Feature;
            TR.UID = User_id;
            db.Train_Features.InsertOnSubmit(TR);
            
                db.SubmitChanges();
               // MessageBox.Show("Feature have been added Successfully ", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            }
            catch (Exception e)
            {
                throw e;
            }

        }
        public List<string> retrive_features_of_certain_id(Int32 id)
        {


            List<String> Features = new List<string>();

            try
            {
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    var feature = from n in db.Train_Features
                                  where n.UID == id //
                                  select n;
                    if (feature != null)
                    {
                        foreach (var n in feature)
                        {
                            Train_Feature temp = n;
                            Features.Add(temp.Features);
                        }
                    }
                    return Features;
                }
            }
            catch (Exception e)
            {
                //return Features;
                throw e;
            }
        }
        public void delete_features_of_certain_id(Int32 id)
        {


           

            try
            {
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    var features = from n in db.Train_Features
                                  where n.UID == id //
                                  select n;
                    if (features != null)
                    {
                        foreach (var n in features)
                        {

                            db.Train_Features.DeleteOnSubmit(n);
                        }
                    }
                    
                }
            }
            catch (Exception e)
            {
               
                throw e;
            }
        }
    }
}
